package com.ego.item.service.impl;

import com.ego.exception.enums.ExceptionEnum;
import com.ego.exception.exception.EgoException;
import com.ego.item.mapper.SpecificationMapper;
import com.ego.item.pojo.Specification;
import com.ego.item.service.SpecificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Slf4j
public class SpecificationServiceImpl implements SpecificationService {

    @Resource
    private SpecificationMapper specificationMapper;

    @Override
    @Transactional(readOnly = true)
    public Specification findSpec(Long cid) {
        Specification specification = null;
        try {
            specification = specificationMapper.selectById(cid);
        }catch (Exception e){
            EgoException.error(log, ExceptionEnum.SPEC_GROUP_NOT_FOUND,e);
        }
        return specification;
    }

    @Override
    @Transactional
    public void insert(Specification specification) {
        try {
            specificationMapper.insert(specification);
        }catch (Exception e){
            EgoException.error(log,ExceptionEnum.SPEC_GROUP_CREATE_FAILED,e);
        }
    }

    @Override
    @Transactional
    public void update(Specification specification) {
        try {
            specificationMapper.updateById(specification);
        }catch (Exception e){
            EgoException.error(log,ExceptionEnum.UPDATE_SPEC_GROUP_FAILED);
        }
    }
}
